/**
 * 基础异常处理类
 */
export class BasicExceptionModel {
  /**
   * 错误提示
   */
  private errorTips = {
    undefined: "出现一个错误",
    0: "OK, 成功",
    1000: "输入参数错误",
    1001: "输入的json格式不正确",
    1002: "找不到资源",
    1003: "未知错误",
    1004: "禁止访问",
    1005: "不正确的开发者key",
    1006: "服务器内部错误",
    2000: "你已经点过赞了",
    2001: "你还没点过赞",
    3000: "该期内容不存在",
  }
  /**
   * 获取错误信息
   * @param obj 
   * @param key 
   */
  private getErrorMsg = (obj: any, key: string) => obj[key] || this.errorTips.undefined

  /**
   * 显示错误提示
   * @param code 
   */
  public showError = (code: number) => {
    wx.showToast({
      title: this.getErrorMsg(this.errorTips, code.toString()),
      icon: "error",
      duration: 2000
    })
  }
}